package com.yc.booktable.biz;

import com.yc.booktable.entity.AdminUser;
import com.yc.booktable.mapper.AdminUserMapper;
import com.yc.booktable.service.impl.AdminUserServiceImpl;
import com.yc.booktable.vo.Result;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class AdminUserBiz {

    @Resource
    private AdminUserServiceImpl adminUserService;
    @Resource
    private AdminUserMapper adminUserMapper;

    public void save(AdminUser adminUser) throws BizException {
        List<AdminUser> adminUsers = adminUserService.selectexid(adminUser.getId());
        /*System.out.println(adminUsers);
        System.out.println("============");
        System.out.println(adminUser);*/
        if(adminUser.getPhone() == null){
            throw new BizException("联系方式不能为空!");
        }
        if(adminUser.getName().trim().isEmpty()){
            throw new BizException("姓名不能为空!");
        }
        if(adminUser.getAccount()==null && adminUser.getAccount().equals("")){
            throw new BizException("账号不能为空!");
        }
        for(AdminUser account : adminUsers){
        if(account.getAccount().equals(adminUser.getAccount())){
                throw new BizException("账号不能重复!");
        }}
        if(adminUser.getPassword()==null){
                throw new BizException("密码不能为空!");
        }
        for(AdminUser email : adminUsers){
        if( email.getEmail().equals(adminUser.getEmail())){
                throw new BizException("邮箱不能为重复!");
        }}
        for(AdminUser phone : adminUsers){
        if(phone.getPhone().equals(adminUser.getPhone())){
                throw new BizException("联系方式不能重复!");
        }}

        adminUserService.saveOrUpdate(adminUser);
    }

}
